/*
 * $Id: Exception.hpp 50 2009-02-10 05:48:05Z hyunghwan.chung $
 *
   Copyright 2005-2009 Chung, Hyung-Hwan.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an  BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

#ifndef _XP_EXCEPTION_CLASS_
#define _XP_EXCEPTION_CLASS_

#include <xp/types.h>
#include <xp/macros.h>

namespace xp
{

#ifdef XP_DEBUG_VERBOSE
	class Exception
	{
	public:
		Exception (
			const xp_char_t* name, const xp_char_t* msg, 
			const xp_char_t* file, int line): 
			name(name), msg(msg), file(file), line(line) {}

		const xp_char_t* name;
		const xp_char_t* msg;
		const xp_char_t* file;
		int   line;
	};

	#define XP_THROW(ex_name) \
		throw ex_name(XP_QUOTE(ex_name),XP_QUOTE(ex_name), XP_T(__FILE__), __LINE__)
	#define XP_THROW_WITH_MSG(ex_name,msg) \
		throw ex_name(XP_QUOTE(ex_name),msg, XP_T(__FILE__), __LINE__)

	#define	XP_EXCEPTION(ex_name) \
		class ex_name: public xp::Exception {  \
		public: \
			ex_name ( \
				const xp_char_t* name, const xp_char_t* msg, \
				const xp_char_t* file, int line): \
				xp::Exception (name, msg, file, line) {} \
		}

	#define XP_EXCEPTION_NAME(exception_object) ((exception_object).name)
	#define XP_EXCEPTION_MSG(exception_object)  ((exception_object).msg)
	#define XP_EXCEPTION_FILE(exception_object) ((exception_object).file)
	#define XP_EXCEPTION_LINE(exception_object) ((exception_object).line)
#else

	class Exception 
	{
	public:
		Exception (const xp_char_t* name, const xp_char_t* msg):
			name(name), msg(msg) {}

		const xp_char_t* name;
		const xp_char_t* msg;
	};

	#define XP_THROW(ex_name) \
		throw ex_name(XP_QUOTE(ex_name),XP_QUOTE(ex_name))
	#define XP_THROW_WITH_MSG(ex_name,msg) \
		throw ex_name(XP_QUOTE(ex_name),msg)

	#define	XP_EXCEPTION(ex_name) \
		class ex_name: public xp::Exception {  \
		public: \
			ex_name (const xp_char_t* name, const xp_char_t* msg): \
				xp::Exception (name, msg) {} \
		}

	#define XP_EXCEPTION_NAME(exception_object) ((exception_object).name)
	#define XP_EXCEPTION_MSG(exception_object)  ((exception_object).msg)
	#define XP_EXCEPTION_FILE(exception_object) (XP_T(""))
	#define XP_EXCEPTION_LINE(exception_object) (0)

#endif

}

#endif
